﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Common;
using Common.Views;

namespace ElectrosLtdApplication.Controllers
{
    public class UpdateFaultController : MenusController
    {
        //
        // GET: /UpdateFault/

        [Authorize]
        public ActionResult Index()
        {
            List<FaultsView> logEntries = new FaultsServ.FaultsServiceClient().GetAllLogEntires().ToList();

            List<SelectListItem> faultsList = new List<SelectListItem>();
            IList<FaultStatu> faults = new FaultsServ.FaultsServiceClient().GetAllFaultStatuses();
            foreach (FaultStatu f in faults)
                faultsList.Add(new SelectListItem { Text = f.Status, Value = f.StatusID.ToString() });

            ViewData["faultList"] = faultsList;
            return View("Index", logEntries);
        }

        [HttpPost]
        public ActionResult UpdateFaultStatus(Guid oId, Guid fId, string fDetails, int sId)
        {
            try
            {
                new FaultsServ.FaultsServiceClient().UpdateFault(oId, fId, fDetails, sId);
                return RedirectToAction("Index", "Home");
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
                return View();
            }
        }
    }
}
